package com.linkoog.devtools.code_generator.database.domain;

import java.util.ArrayList;
import java.util.List;

public class TableInfo {

    private String tableName;
    private String tableComment;
    private boolean checked;


    private String javaEntityName;
    private List<ColumnInfo> columnInfos;


    public TableInfo(){
        this.tableComment = "";
        this.checked = false;
    }

    public TableInfo(String tableName, String tableComment) {
        this(tableName, tableComment,false);
    }

    public TableInfo(String tableName, String tableComment, boolean checked) {
        this();
        this.tableName = tableName;
        this.tableComment = tableComment;
        this.checked = checked;
    }

    public TableInfo deepCopyWithCheckColumn(){
        TableInfo tableInfo = new TableInfo();
        tableInfo.tableName = this.tableName;
        tableInfo.tableComment = this.tableComment;
        tableInfo.checked = this.checked;

        tableInfo.javaEntityName = this.javaEntityName;
        List<ColumnInfo> columnInfoList = new ArrayList<>();
        tableInfo.columnInfos = columnInfoList;
        for (ColumnInfo columnInfo : columnInfos) {
            if(columnInfo != null && columnInfo.getChecked()){
                columnInfoList.add(columnInfo.deepCopy());
            }
        }

        return tableInfo;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;

    }

    public String getTableComment() {
        return tableComment;
    }

    public void setTableComment(String tableComment) {
        this.tableComment = tableComment;
    }

    public boolean getChecked() {
        return checked;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    public String getJavaEntityName() {
        return javaEntityName;
    }

    public void setJavaEntityName(String javaEntityName) {
        this.javaEntityName = javaEntityName;
    }

    public List<ColumnInfo> getColumnInfos() {
        return columnInfos;
    }

    public void setColumnInfos(List<ColumnInfo> columnInfos) {
        this.columnInfos = columnInfos;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("com.github.linkoog.crud.database.domain.TableInfo{");
        sb.append("tableName='").append(tableName).append('\'');
        sb.append(", tableComment='").append(tableComment).append('\'');
        sb.append(", checked=").append(checked);
        sb.append(", javaEntityName='").append(javaEntityName).append('\'');
        sb.append(", columnInfos=").append(columnInfos);
        sb.append('}');
        return sb.toString();
    }
}
